home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
turbovis
/
tvtoys04.zip
/
VIDEO.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-12-10
|
15KB
|
557 lines
(***************************************************************************
Video unit
Video mode routines, trial and error legal mode detection
PJB August 29, 1993, Internet mail to d91-pbr@nada.kth.se
Copyright 1993, All Rights Reserved
Free source, use at your own risk.
If modified, please state so if you pass this around.
Intended for Turbo Vision, easily rehacked.
■ Use CheckVideoType to initialize before you call any
other procedures or access any variables in this unit.
■ Use ScanEVGAModes only on EGA and VGA compatible cards, or else
the results might be misleading. Check this before you use
ScanEVGAModes.
If the video card is VERY old, the computer might crash since the
BIOSes weren't designed to handle "illegal" video modes back then...
For full VESA, Video7 support, use only SetSpecialVideoMode and
GetSpecialVideoMode from this unit.
You can overlay this unit only if AutoCheckVideoType is not defined.
See CONFIG.PAS for a description of all conditional defines.
***************************************************************************)
unit Video;
{$I toyCfg}
{$B-,Q-,S-,X+}
{$IFDEF DPMI} {$G+} {$ENDIF}
{$IFNDEF AutoCheckVideoType}
{$O+}
{$ENDIF}
interface
uses
{$IFDEF DPMI}
DPMI,
WinAPI,
{$ENDIF}
{$IFDEF VesaSupport}
VESA,
{$ENDIF}
Drivers;
type
AddModeProc = procedure (Mode, Rows, Columns, CharHeight:Word; Color:boolean);
(*******************************************************************
Video BIOS stuff
*******************************************************************)
const
CrtWidth = $4A; (* byte *)
CrtSize = $4C; (* word *)
Addr6845 = $63; (* word *)
CrtRows = $84; (* byte EGA/VGA *)
CrtPoints = $85; (* byte EGA/VGA *)
CrtInfo = $87; (* byte EGA/VGA *)
(* Use with UseInternalFont *)
Internal8x8Font = $12;
Internal8x14Font = $11;
Internal8x16Font = $14;
(*******************************************************************
Video mode detection stuff
*******************************************************************)
type
VideoTypes = (Other, EGA, VGA);
SpecialVideoTypes = set of (vtVesa, vtVideo7);
const
(* This value can be used to rule out Vesa and V7 tests run-time *)
VideoTypesToCheck : SpecialVideoTypes = [vtVesa, vtVideo7];
var
(* Detected video type *)
VideoType : VideoTypes;
{$IFDEF Video7Support}
Video7 : boolean;
const
V7Installed = 1;
HPInstalled = 2;
{$ENDIF}
const
{$IFDEF VesaSupport}
DontClearVideoModeFlag : Word = $80;
{$ELSE}
DontClearVideoModeFlag = $80;
{$ENDIF}
type
ModeSet = set of 0..127;
const
(* 0,1 intentionally left out *)
StandardTextModes : ModeSet = [2, 3, 7];
VGAModes : ModeSet = [2, 3, 7, 8, $14..127];
VESAModes : ModeSet = [$8..$C]; (* Corresponds to $108..$10C *)
(*******************************************************************
Video state object
*******************************************************************)
type
VideoState =
object
Mode : Word;
Lines : Byte;
CharHeight : Byte;
procedure Save;
procedure Restore;
end;
procedure SetSpecialVideoMode(Mode:Word);
function GetSpecialVideoMode:Word;
{$IFDEF VesaSupport}
procedure CheckVesa;
{$ENDIF}
{$IFDEF Video7Support}
procedure CheckVideo7;
{$ENDIF}
procedure CheckEVGA;
procedure CheckVideoType;
function GetCurrentScanLines:Integer;
procedure UseInternalFont(Font:Byte);
procedure LoadUserFont(Points:Byte; First, Count:Integer; Font:Pointer); function IsProbablyTextMode:Boolean;
function IsColorMode:Boolean;
procedure ScanEVGAModes(ModeOffset:Word; const ModesToCheck:ModeSet; AddMode:AddModeProc);
(***************************************************************************
***************************************************************************)
implementation
{$IFDEF Video7Support}
(*******************************************************************
Test for the presence of a Video7 or HP video card
*******************************************************************)
function V7orHPInstalled:Byte; assembler;
asm
mov ax,6F00h
xor bx,bx
int 10h
mov al,V7Installed
cmp bx,'V7'
je @Fin
mov al,HPInstalled
cmp bx,'HP'
je @Fin
mov al,0
@Fin:
end;
{$ENDIF}
(*******************************************************************
Set video mode using VESA, Video7 or BIOS, if supported and present
*******************************************************************)
procedure SetSpecialVideoMode(Mode:Word); assembler;
asm
mov ax,Mode
{$IFDEF VesaSupport}
cmp VESA.VesaVersion,0
je @NoVesa
push ax
call VESA.SetVesaMode
cmp al,4Fh (* Supported? *)
je @Fin
mov bx,Mode
test bh,7Fh
jne @Fin
mov al,bh
and al,80h
or al,bl
@NoVesa:
{$ENDIF}
{$IFDEF Video7Support}
cmp Video7,False
je @Go
mov bl,al
mov ax,6F05h
{$ENDIF}
@Go:
int 10h
@Fin:
end;
(*******************************************************************
Retrieve current video from VESA, Video7 or plain BIOS
*******************************************************************)
function GetSpecialVideoMode:Word; assembler;
asm
{$IFDEF VesaSupport}
cmp VESA.VesaVersion,0
je @NoVesa
call VESA.GetVesaMode
and ah,7Fh
{$IFDEF V7UniVesaKludge}
{$IFDEF Video7Support}
cmp Video7,False
je @NoV7Test
{$ENDIF}
cmp ax,1 (* Boring bad VESA driver returns this on V7 *)
je @NoVesa
@NoV7Test:
{$ENDIF}
cmp bx,4Fh (* Success? *)
je @Fin
@NoVesa:
{$ENDIF}
{$IFDEF Video7Support}
cmp Video7,False
je @NoV7
mov ax,6F04h
int 10h
jmp @ClearAH
{$ENDIF}
@NoV7:
mov ah,0Fh
int 10h
@ClearAH:
and ax,7Fh
@Fin:
end;
(*******************************************************************
Vesa present?
*******************************************************************)
{$IFDEF VesaSupport}
procedure CheckVesa; assembler;
asm
call DetectVesaVersion
cmp VesaVersion,0
je @NoVesa
mov DontClearVideoModeFlag,8000h
@NoVesa:
end;
{$ENDIF}
(*******************************************************************
Video 7 card?
*******************************************************************)
{$IFDEF Video7Support}
procedure CheckVideo7; assembler;
asm
call V7orHPInstalled
cmp al,0
je @NoV7
mov al,1
@NoV7:
mov Video7,al
end;
{$ENDIF}
(*******************************************************************
EGA, VGA or Other?
*******************************************************************)
procedure CheckEVGA; assembler;
asm
push bp
mov VideoType,Other
mov ax,1200h
mov bx,10h
mov cx,0FFFFh
int 10h
inc cx
je @Fin (* No EGA support *)
mov VideoType,EGA
mov ax,1A00h
int 10h
cmp al,1Ah
jne @Fin (* Not a VGA or PS/2 type card *)
cmp bl,7
jae @VGA (* VGA, MCGA *)
cmp bl,4 (* EGA *)
jae @Fin
mov VideoType,Other (* Something else *)
jmp @Fin
@VGA:
mov VideoType,VGA
@Fin:
pop bp
end;
(*******************************************************************
Check w